Menu

Testing Multiple Scenarios

Kelly Ethridge

Sometimes you want to test a method using many values. You could create explicit unit-tests for each scenario you wish to test, but with SimplyVBUnit multiple test scenarios can easily be created by implementing the ITestCaseSource interface on a test class.

By implementing this interface, you are given the ability to define multiple scenarios for unit-tests that accept parameters in their method signature.

ITestCaseSource Example

When ITestCaseSource is implemented, a set of cohesive tests can be defined.

Sometimes the assertion made in the test isn't the one needed for a specific scenario. One solution is to create another test method utilizing the specific assertion required. However, ITestCaseSource allows for return values from the test method and invoking a unique assertion constraint for each defined scenario.

An updated test method demonstrates utilizing a return value.

ITestCaseSource Example

As you can see, creating multiple test scenarios can be done very easily, allowing you to focus on your code instead of building similar test methods.


Related

Wiki: Writing Unit-Tests